<?php

    require_once('../tcpdf/tcpdf.php');
    class PDFCreator extends TCPDF
    {

        protected $author = 'Admin';
        protected $title = '内部办公文档';
        protected $subjet = '内部办公文档';
        protected $keywords = '翠屏区公安局 财务报销 业务审批';
        protected $pdf = null;

        //创建数字大写的函数
        private function _createCaptialNum($num)
        {
            switch ($num) {
                case 1:
                    return '壹';
                case 2:
                    return '贰';
                case 3:
                    return '叁';
                case 4:
                    return '肆';
                case 5:
                    return '伍';
                case 6:
                    return '陆';
                case 7:
                    return '柒';
                case 8:
                    return '捌';
                case 9:
                    return '玖';
                case 0:
                    return '零';
            }
        }

        //创建人民币大写的函数
        function createCaptitalRMB($rmb)
        {
            $str = '';

            $t = intval(intval($rmb) / 10000);
            $str .= $this->_createCaptialNum($t) . ' 万 ';

            $t = intval(intval($rmb) % 10000 / 1000);
            $str .= $this->_createCaptialNum($t) . ' 仟 ';

            $t = intval(intval($rmb) % 1000 / 100);
            $str .= $this->_createCaptialNum($t) . ' 佰 ';

            $t = intval(intval($rmb) % 100 / 10);
            $str .= $this->_createCaptialNum($t) . ' 拾 ';

            $t = intval($rmb) % 10;
            $str .= $this->_createCaptialNum($t) . ' 元 ';

            $temp = $rmb * 100;
            $t = intval($temp % 100 / 10);
            $str .= $this->_createCaptialNum($t) . ' 角 ';

            $t = $temp % 10;
            $str .= $this->_createCaptialNum($t) . ' 分 ';

            return $str;
        }

        //银行卡号分开的函数
        function createBankCard($card)
        {
            $cardStr = "";
            for ($i = 0; $i < strlen($card); $i++) {
                $cardStr .= $card[$i];
                if (($i + 1) % 4 == 0) {
                    $cardStr .= "&nbsp;";
                }
            }
            return $cardStr;
        }


        function __construct()
        {
            $this->pdf = new TCPDF("P", 'mm', 'A4', true, 'UTF-8', false);
            $this->pdf->SetCreator(PDF_CREATOR);
            $this->pdf->SetAuthor($this->author);
            $this->pdf->SetSubject($this->subjet);
            $this->pdf->SetTitle($this->title);
            $this->pdf->SetKeywords($this->keywords);

            // set header and footer fonts
            $this->pdf->setHeaderFont(Array('cid0cs', 'I', 12));
            $this->pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

            // set default monospaced font
            $this->pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

            // set margins
            $this->pdf->SetMargins(PDF_MARGIN_LEFT, 15, PDF_MARGIN_RIGHT);
            $this->pdf->SetHeaderMargin(2);
            $this->pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

            // set auto page breaks
            $this->pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

            // set image scale factor
            $this->pdf->setImageScale(1.25);

            $this->pdf->SetFont('cid0cs', '', 10, 'tcpdf/fonts/cid0cs.php', true);


        }

        //分开同行人员
        private function createPartnerStr($comp){
            $str='';
            for($i = 0; $i < (count($comp) > 15 ? 15 : count($comp)); $i++){
                $str .= $comp[$i]['comp_user_name']."-".$comp[$i]['comp_depart_name'].";";
                if(($i+1) % 4 == 0){
                    $str .='\n';
                }
            }
            return $str;
        }

        function createOverStandardPDF($applyData, $hasImage = false){
            $this->pdf->setHeaderData('jinhui.png', 10, '', '宜宾市翠屏区公安局-超标费用报销单', array(0, 0, 0), array(0, 0, 0));
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
            $this->pdf->AddPage();

            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));

            $this->pdf->Ln(5);
            $curWidth = $this->pdf->getPageWidth() - $this->pdf->getMargins()['left'] - $this->pdf->getMargins['right'];
            $curHeight = $this->pdf->getPageHeight() - $this->pdf->getHeaderMargin() - $this->pdf->getFooterMargin();

            $leftWidth = $curWidth / 4;
            $rightWidth = $curWidth / 4 * 3 - $this->pdf->getMargins()['right'];

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '部门', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['section_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($leftWidth, $curHeight / 25*3 , "出差人员姓名", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25*3 , 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25*3 , $this->createPartnerStr($applyData['comp']), 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 3 , 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25*10 , "超标事由", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25*10 , 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25*10 , $applyData['over_reason'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 10 , 'M');

            //文件路径应该获取，分别从三个签批人ID+.jpg获取
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3.75, "部门负责人(签字加盖公章)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_manager_ID'] && $hasImage){
//                $this->pdf->($this->pdf->getMargins()['left'] + 2, $this->pdf->getHeaderMargin() + $curHeight - 60, '同意出差');
                $this->pdf->Image('images/sign/' . $applyData['section_manager_ID'] . '.jpg',
                    $this->pdf->getMargins()['left'] + 17, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            }

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "分局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['section_leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + 35, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 1, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');

            if ($applyData['leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + $rightWidth / 2 + 30, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->Ln(1);
            $this->pdf->MultiCell($leftWidth, $curHeight / 40, '经办人:', 0, 'J', 1, 0, '', '', true, 0, false, true, $curHeight / 40, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 40, '年             月             日', 0, 'R', 1, 0, '', '', true, 0, false, true, $curHeight / 40);
            //$this->pdf->Output('1.pdf', 'I');
            $this->pdf->Output(dirname(__FILE__) . '/temp/overstandard/' . $applyData['over_standard_id'] . '.pdf', 'F');
            return 'PDF/temp/overstandard/' . $applyData['over_standard_id'] . '.pdf';
        }

        //嫌疑人费用报销单
        function createSuspectFeePDF($applyData, $hasImage = false){

            $this->pdf->setHeaderData('jinhui.png', 10, '', '宜宾市翠屏区公安局-嫌疑人费用报销单', array(0, 0, 0), array(0, 0, 0));
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
            $this->pdf->AddPage();

            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));

            $this->pdf->Ln(5);
            $curWidth = $this->pdf->getPageWidth() - $this->pdf->getMargins()['left'] - $this->pdf->getMargins['right'];
            $curHeight = $this->pdf->getPageHeight() - $this->pdf->getHeaderMargin() - $this->pdf->getFooterMargin();

            $leftWidth = $curWidth / 4;
            $rightWidth = $curWidth / 4 * 3 - $this->pdf->getMargins()['right'];

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '部门', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['section_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($leftWidth, $curHeight / 25*3 , "嫌疑人名单", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25*3 , 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25*3 , $applyData['suspect_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 3 , 'M');
            $total_fee = $applyData['suspect_life_fee'] + $applyData['suspect_other_fee'] + $applyData['suspect_road_fee'];

            $fee_info = "
                    <br/><br/><br/><table>
                        <tr>
                            <td>嫌疑人生活费用：</td>
                            <td>".sprintf('%.2f',$applyData['suspect_life_fee'])."</td>
                        </tr>
                        <tr>
                            <td>嫌疑人交通费用：</td>
                            <td>".sprintf('%.2f',$applyData['suspect_road_fee'])."</td> 
                        </tr>
                        <tr>
                            <td>嫌疑人其它费用：</td>
                            <td>".sprintf('%.2f',$applyData['suspect_other_fee'])."</td> 
                        </tr>
                        
                        <tr>
                            <td>总计(小写):</td>
                            <td>".sprintf('%.2f',$total_fee)."</td>
                        </tr>
                        <tr>
                            <td>总计(大写):</td>
                            <td>".$this->createCaptitalRMB($total_fee)."</td>
                        </tr>
                    </table>";
            // $test = "测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n";
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 4, '费用构成', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 4, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 4, $fee_info, 1, 'C', 1, 1, '', '', true, 0, true, true, $curHeight / 25 * 4, 'M');
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 , "是否有票", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 , 'M');
            $has_receipe = $applyData['has_receipe'] == 0 ? '否' : '是';
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 , $has_receipe, 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 , 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 7, "无票理由", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 7, 'M');
            $reason = $applyData['has_receipe'] == 0 ? $applyData['no_receipe_reason'] : '有发票';
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 7, $reason, 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 7, 'M');


            //文件路径应该获取，分别从三个签批人ID+.jpg获取
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3.75, "部门负责人(签字加盖公章)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_manager_ID'] && $hasImage){
//                $this->pdf->($this->pdf->getMargins()['left'] + 2, $this->pdf->getHeaderMargin() + $curHeight - 60, '同意出差');
                $this->pdf->Image('images/sign/' . $applyData['section_manager_ID'] . '.jpg',
                    $this->pdf->getMargins()['left'] + 17, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            }

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "分局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['section_leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + 35, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 1, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');

            if ($applyData['leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + $rightWidth / 2 + 30, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->Ln(1);
            $this->pdf->MultiCell($leftWidth, $curHeight / 40, '经办人:', 0, 'J', 1, 0, '', '', true, 0, false, true, $curHeight / 40, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 40, '年             月             日', 0, 'R', 1, 0, '', '', true, 0, false, true, $curHeight / 40);

            $this->pdf->Output(dirname(__FILE__) . '/temp/suspectfee/' . $applyData['suspect_ID'] . '.pdf', 'F');
            return 'PDF/temp/suspectfee/' . $applyData['suspect_ID'] . '.pdf';
        }
        //创建借款单PDF
        function createLoanFeePDF($applyData, $hasImage = false){

            $this->pdf->setHeaderData('jinhui.png', 10, '', '宜宾市翠屏区公安局-借款审批单', array(0, 0, 0), array(0, 0, 0));
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
            $this->pdf->AddPage();

            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));


            $curWidth = $this->pdf->getPageWidth() - $this->pdf->getMargins()['left'] - $this->pdf->getMargins['right'];
            $curHeight = $this->pdf->getPageHeight() - $this->pdf->getHeaderMargin() - $this->pdf->getFooterMargin();

            $leftWidth = $curWidth / 4;
            $rightWidth = $curWidth / 4 * 3 - $this->pdf->getMargins()['right'];
            $this->pdf->MultiCell($leftWidth, $curHeight / 40, '借款单编号:'.$applyData['loan_money_id'], 0, 'J', 1, 0, '', '', true, 0, false, true, $curHeight / 40, 'M');
            $this->pdf->Ln(8);
            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '部门', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['section_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 , "借款人", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 , 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 , $applyData['user_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 , 'M');
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 , "预借金额", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 , 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 , $applyData['money'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 , 'M');

            // $test = "测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n";
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 7, '借款事由', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 7, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 7, $applyData['reason'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 7, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 6, "借条\n(借款人员在出纳办公室借款时当面填写)", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 6, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 6, '', 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 6, 'M');


            //文件路径应该获取，分别从三个签批人ID+.jpg获取
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3.75, "部门负责人(签字加盖公章)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意借款</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_manager_ID'] && $hasImage){
//                $this->pdf->($this->pdf->getMargins()['left'] + 2, $this->pdf->getHeaderMargin() + $curHeight - 60, '同意出差');
                $this->pdf->Image('images/sign/' . $applyData['section_manager_ID'] . '.jpg',
                    $this->pdf->getMargins()['left'] + 17, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            }

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "分局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意借款</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['section_leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + 35, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意借款</h1>", 1, 'J', 1, 1, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');

            if ($applyData['leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + $rightWidth / 2 + 30, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->Ln(1);
            $this->pdf->MultiCell($leftWidth, $curHeight / 40, '经办人:', 0, 'J', 1, 0, '', '', true, 0, false, true, $curHeight / 40, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 40, '年             月             日', 0, 'R', 1, 0, '', '', true, 0, false, true, $curHeight / 40);

            $this->pdf->Output(dirname(__FILE__) . '/temp/loanfee/' . $applyData['loan_money_id'] . '.pdf', 'F');
            return 'PDF/temp/loanfee/' . $applyData['loan_money_id'] . '.pdf';

        }
        //创建借车单PDF
        function createLoanCarPDF($applyData, $hasImage = false){
            $this->pdf->setHeaderData('jinhui.png', 10, '', '宜宾市翠屏区公安局-借车审批单', array(0, 0, 0), array(0, 0, 0));
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
            $this->pdf->AddPage();

            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));

            $this->pdf->Ln(5);
            $curWidth = $this->pdf->getPageWidth() - $this->pdf->getMargins()['left'] - $this->pdf->getMargins['right'];
            $curHeight = $this->pdf->getPageHeight() - $this->pdf->getHeaderMargin() - $this->pdf->getFooterMargin();

            $leftWidth = $curWidth / 4;
            $rightWidth = $curWidth / 4 * 3 - $this->pdf->getMargins()['right'];

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '部门', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['section_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3, "借车人员\n(附驾驶证正副本复印件)", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 3, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 3, $applyData['user_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 3, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3, '预借车辆号牌', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 3, 'M');

            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 3, $applyData['carNum'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 3, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 8, '借车事由', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 8, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 8, $applyData['reason'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 8, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '专职驾驶员', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, ($applyData['driver_name'] == '' ? '无' : $applyData['driver_name']) , 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');

            //文件路径应该获取，分别从三个签批人ID+.jpg获取
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3.75, "部门负责人(签字加盖公章)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意借车</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_manager_ID'] && $hasImage){
//                $this->pdf->($this->pdf->getMargins()['left'] + 2, $this->pdf->getHeaderMargin() + $curHeight - 60, '同意出差');
                $this->pdf->Image('images/sign/' . $applyData['section_manager_ID'] . '.jpg',
                    $this->pdf->getMargins()['left'] + 17, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            }

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "分局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意借车</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['section_leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + 35, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意借车</h1>", 1, 'J', 1, 1, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');

            if ($applyData['leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + $rightWidth / 2 + 30, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->Ln(1);
            $this->pdf->MultiCell($leftWidth, $curHeight / 40, '经办人:', 0, 'J', 1, 0, '', '', true, 0, false, true, $curHeight / 40, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 40, '年             月             日', 0, 'R', 1, 0, '', '', true, 0, false, true, $curHeight / 40);

            $this->pdf->Output(dirname(__FILE__) . '/temp/loancar/' . $applyData['loan_car_id'] . '.pdf', 'F');
            return 'PDF/temp/loancar/' . $applyData['loan_car_id'] . '.pdf';


        }
        //创建出差审批单PDF
        function createBusinessApplyPDF($applyData, $hasImage = false)
        {
            $this->pdf->setHeaderData('jinhui.png', 10, '', '宜宾市翠屏区公安局-出差审批单', array(0, 0, 0), array(0, 0, 0));
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
            $this->pdf->AddPage();
            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));

            $this->pdf->Ln(5);
            $curWidth = $this->pdf->getPageWidth() - $this->pdf->getMargins()['left'] - $this->pdf->getMargins['right'];
            $curHeight = $this->pdf->getPageHeight() - $this->pdf->getHeaderMargin() - $this->pdf->getFooterMargin();

            $leftWidth = $curWidth / 4;
            $rightWidth = $curWidth / 4 * 3 - $this->pdf->getMargins()['right'];

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '部门', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['section_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3.75, '出差人员', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 3.75, 'M');

            // $test = "测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n";

            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 3.75, $applyData['companion'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 3.75, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 9, '出差事由', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 9, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 9, $applyData['reason'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 9, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '出差目的地', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['destination'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '预计出差时间', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['timerange'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '是否自驾车', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['self_drive'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');

            //文件路径应该获取，分别从三个签批人ID+.jpg获取
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3.75, "部门负责人(签字加盖公章)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意出差</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_manager'] && $hasImage){
//                $this->pdf->($this->pdf->getMargins()['left'] + 2, $this->pdf->getHeaderMargin() + $curHeight - 60, '同意出差');
                $this->pdf->Image('images/sign/' . $applyData['section_manager'] . '.jpg',
                    $this->pdf->getMargins()['left'] + 17, $this->pdf->getHeaderMargin() + $curHeight - 42, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            }

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "分局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意出差</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_leader'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['section_leader'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + 35, $this->pdf->getHeaderMargin() + $curHeight - 42, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意出差</h1>", 1, 'J', 1, 1, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');

            if ($applyData['leader'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['leader'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + $rightWidth / 2 + 30, $this->pdf->getHeaderMargin() + $curHeight - 42, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->Ln(1);
            $this->pdf->MultiCell($leftWidth, $curHeight / 40, '经办人:', 0, 'J', 1, 0, '', '', true, 0, false, true, $curHeight / 40, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 40, '年             月             日', 0, 'R', 1, 0, '', '', true, 0, false, true, $curHeight / 40);

            $this->pdf->Output(dirname(__FILE__) . '/temp/busapp/' . $applyData['appID'] . '.pdf', 'F');
            return 'PDF/temp/busapp/' . $applyData['appID'] . '.pdf';

        }

        //创建差旅报销单
        function createBusinessSubmit($applyData, $hasImage = false)
        {
            // set default header data
            $this->pdf->setHeaderData('jinhui.png', 10, '', '宜宾市翠屏区公安局-差旅报销单', array(0, 0, 0), array(0, 0, 0));
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));


            // Add a page
            // This method has several options, check the source code documentation for more information.
            $this->pdf->AddPage();
            $this->pdf->SetMargins(-5, 0, 10);

            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));

            $len = count($applyData['apply_detail']);
            $tableNum = ceil($len / 5);

            for($i = 0; $i < $tableNum; $i++){
                $tableData = array_slice($applyData['apply_detail'], $i * 5, 5);


                if(count($tableData) < 5){
                    for($j = count($tableData); $j < 5; $j++){
                        $tableData[$j] = array(
                            'depart_time'=>'', 'depart_city'=>'', 'arrive_time'=>'', 'arrive_city'=>'',
                            'car_fee'=>'', 'boat_fee'=>'', 'flight_fee'=>'', 'road_days'=>'',
                            'stay_days'=>'', 'total_days'=>'', 'hotel_fee'=>'', 'food_fee'=>'',
                            'inci_fee'=>'', 'other_fee'=>'', 'suspect_fee'=>'', 'reward_fee'=>'',
                            'car_main_fee'=>'', 'oil_fee'=>'', 'pass_fee'=>'', 'distance'=>'');
                    }
                }
                if(($i + 1) % 3 == 1 && (($i + 1) / 3 >= 1)){
                    $this->pdf->AddPage();
                }

                $this->_createBusinessSubmitContent($applyData, $tableData, $i+1);
            }

            // $this->pdf->Output("1.pdf", 'I');
            $this->pdf->Output(dirname(__FILE__) . '/temp/fee/' . $applyData['fee_id'] . '.pdf', 'F');
            return '/PDF/temp/fee/' . $applyData['fee_id'] . '.pdf';
            //return $this->_createBusinessSubmitContent($applyData, $hasImage);

        }

        //测试函数，创建借款报销单，新
        function createNewLoanFeePDF($applyData, $hasImage = false){
            // set default header data
            $this->pdf->setHeaderData('jinhui.png', 15, '', '宜宾市翠屏区公安局-差旅报销单', array(0, 0, 0), array(0, 0, 0));
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));


            // Add a page
            // This method has several options, check the source code documentation for more information.
            $this->pdf->AddPage();

            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
            $this->pdf->Ln(5);
            $html = '
               <table width="100%" border="0" style="font-size:10px">
                   <tr>
                         <td align="left">部门：'.$applyData['section_name'].'</td>
                         <td align="right">借款单号:'.$applyData['loan_money_id'].'</td>
                   </tr> 
               </table>
               <table width="100%" border="1" style="font-size:12px">
                   <tr>
                       <td align="center" >借款人</td>
                       <td align="center" colspan="2">'.$applyData['user_name'].'</td>           
                       <td align="center">借款金额</td>
                       <td align="center" colspan="2">'.sprintf('%.2f', $applyData['money']).'</td>         
                   </tr>
                   <tr>
                       <td align="center" rowspan="4"><p><br/>借款事由</p></td>
                       <td align="center" colspan="5" rowspan="4">'.$applyData['reason'].'</td>
                   </tr>
                   <tr>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                   </tr>
                   <tr>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                   </tr>
                      <tr>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                       <td></td>
                   </tr>
               </table>
               <table width="100%" border="1" style="font-size:12px">
                   <tr>
                        <td align="left" >         
                            <span>部门负责人<i>(签字并加盖部门公章)</i></span><br/><br/><br/>
                            <div style="text-align:left;line-height:4px"><h2>&nbsp;&nbsp;同意借款</h2></div>
                            <div style="text-align:right;line-height:3px">'.
                ($hasImage ? '<img src="images/sign/'.$applyData['section_manager_ID'].'.jpg" width="60" height="30px">' :
                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img width="60px" height="30px">').'</div>'.'
                        </td>
                        <td align="left" >         
                            <span>分管局领导<i>(签字)</i></span><br/><br/><br/>
                            <div style="text-align:left;line-height:4px"><h2>&nbsp;&nbsp;同意借款</h2></div>
                            <div style="text-align:right;line-height:3px">'.
                ($hasImage ? '<img src="images/sign/'.$applyData['section_leader_ID'].'.jpg" width="60" height="30px">' :
                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img width="60px" height="30px">').'</div>'.'
                        </td>
                        <td align="left" >         
                            <span>局领导<i>(签字)</i></span><br/><br/><br/>
                            <div style="text-align:left;line-height:4px"><h2>&nbsp;&nbsp;同意借款</h2></div>
                            <div style="text-align:right;line-height:3px">'.
                ($hasImage ? '<img src="images/sign/'.$applyData['leader_ID'].'.jpg" width="60" height="30px">' :
                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img width="60px" height="30px">').'</div>'.'
                        </td>
                    </tr>
               </table>
               <table width="100%" border="0" style="font-size:10px">
                   <tr>
                       <td align="left">经办人：</td>
                       <td align="right">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日</td>
                   </tr>     
               </table>';
            $this->pdf->writeHTML($html, true, false, true, false, '');
            $this->pdf->Output('test.pdf', 'I');

        }

        //创建业务报销单的函数
        function createOrdinaryFeeApprovePDF($applyData, $hasImage = false){
            $this->pdf->setHeaderData('jinhui.png', 10, '', '宜宾市翠屏区公安局-费用报销单', array(0, 0, 0), array(0, 0, 0));
          //  $this->pdf->setPrintHeader(false);
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
            $this->pdf->AddPage();


            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
            $len = count($applyData['data']);
            $tableNum = ceil($len / 5);
         //   echo $tableNum;
            $loan_fee = $applyData['loan_fee'];
            for($i = 0; $i < $tableNum; $i++){
                $tableData = array_slice($applyData['data'], $i * 5, 5);


                if(count($tableData) < 5){
                    for($j = count($tableData); $j < 5; $j++){
                        $tableData[$j] = array('fee_item_id'=>'', 'fee_item'=>'', 'fee_type'=>'', 'fee_type_name'=>'', 'money'=>'', 'fuhe_money'=>'');
                    }
                }
                if(($i + 1) % 3 == 1 && (($i + 1) / 3 >= 1)){
                    $this->pdf->AddPage();
                }


               $this->_createOrdinaryFeeTable($applyData, $tableData, $i+1, $loan_fee, $hasImage);
            }
            $this->pdf->Output(dirname(__FILE__) . '/temp/ordinaryFee/' . $applyData['fee_id'] . '.pdf', 'F');
            return '/PDF/temp/ordinaryFee/' . $applyData['fee_id'] . '.pdf';

        }

        //实际创建业务报销单PDF的函数
        private function _createOrdinaryFeeTable($appData, $tableData, $id, $loan_fee, $hasImage){
            $state = $appData['state'];
            $total_fee = ($state == 3 ? $appData['fuhe_total_fee'] : $appData['pre_total_fee'] );
            $pre_loan_fee = $loan_fee;

            $loan_fee -= $total_fee;
//            for($i = 0; $i < count($tableData); $i++){
                $html = '
                      <table width="100%" border="0" style="font-size: 20px">
                        <tr>
                           <td align="center"><b style="border-bottom:1px solid black">费&nbsp;&nbsp;用&nbsp;&nbsp;报&nbsp;&nbsp;销&nbsp;&nbsp;单</b></td>
                        </tr>
                        </table>
                        <br/>
                          <br/>
                        <table width="100%" border="0" style="font-size: 10px">
                        <tr>
                           <td align="center" colspan="2">部门.'.$appData['section_name'].'</td>
                           <td align="center">'.date('Y'). '年'.date('m').'月'.date('d').'日</td>
                           <td align="center">附件</td>
                           <td align="center">张</td>
                        </tr>
                        </table>
                        <table width="100%" border="1" style="font-size: 10px">
                        <tr style="height:20px; line-height: 20px">
                           <td align="center" colspan="2">费用项目</td>
                           <td align="center">类别</td>
                           <td align="center">填报金额</td>
                           <td align="center">复核金额</td>
                           <td align="center" rowspan="2">部门审批</td>
                           <td align="center" rowspan="2">
                               <div style="text-align:left;line-height:4px"><h3>同意报销</h3>'.'
                               <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                               .($hasImage ? '<img src="../images/sign/'.$appData['section_manager_ID'].'.jpg" width="30" height="15px"></span>' : '</span>')
                    .'</div>
                              
                           </td>
                        </tr>
                        <tr style="height:20px; line-height: 20px">
                           <td align="center" colspan="2">'.$tableData[0]['fee_item'].'</td>
                           <td align="center">'.$tableData[0]['fee_type_name'].'</td>
                           <td align="center">'.$tableData[0]['money'].'</td>
                           <td align="center">'.($state == 3 ? $tableData[0]['fuhe_money'] : '').'</td>
                        </tr>
                        <tr style="height:20px; line-height: 20px">
                           <td align="center" colspan="2">'.$tableData[1]['fee_item'].'</td>
                           <td align="center">'.$tableData[1]['fee_type_name'].'</td>
                           <td align="center">'.$tableData[1]['money'].'</td>
                           <td align="center">'.($state == 3 ? $tableData[1]['fuhe_money'] : '').'</td>
                           <td align="center" rowspan="2">分管审批</td>
                           <td align="center" rowspan="2">
                               <div style="text-align:left;line-height:4px"><h3>同意报销</h3>'.'
                               <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                    .($hasImage ? '<img src="../images/sign/'.$appData['section_leader_ID'].'.jpg" width="30" height="15px"></span>' : '</span>')
                    .'</div>
                           </td>
                        </tr>
                        <tr style="height:20px; line-height: 20px">
                         <td align="center" colspan="2">'.$tableData[2]['fee_item'].'</td>
                           <td align="center">'.$tableData[2]['fee_type_name'].'</td>
                           <td align="center">'.$tableData[2]['money'].'</td>
                           <td align="center">'.($state == 3 ? $tableData[2]['fuhe_money'] : '').'</td>
                        </tr>
                         <tr style="height:20px; line-height: 20px">
                           <td align="center" colspan="2">'.$tableData[3]['fee_item'].'</td>
                           <td align="center">'.$tableData[3]['fee_type_name'].'</td>
                           <td align="center">'.$tableData[3]['money'].'</td>
                           <td align="center">'.($state == 3 ? $tableData[3]['fuhe_money'] : '').'</td>
                           <td align="center" rowspan="2">领导审批</td>
                           <td align="center" rowspan="2">    <div style="text-align:left;line-height:4px"><h3>同意报销</h3>'.'
                               <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                    .($hasImage ? '<img src="../images/sign/'.$appData['leader_ID'].'.jpg" width="30" height="15px"></span>' : '</span>')
                    .'</div></td>
                        </tr>
                        <tr style="height:20px; line-height: 20px">
                      <td align="center" colspan="2">'.$tableData[4]['fee_item'].'</td>
                           <td align="center">'.$tableData[4]['fee_type_name'].'</td>
                           <td align="center">'.$tableData[4]['money'].'</td>
                           <td align="center">'.($state == 3 ? $tableData[4]['fuhe_money'] : '').'</td>
                        </tr>
                        <tr style="height:20px; line-height: 20px">
                          <td align="center">合计金额(大写)</td>
                          <td align="center" colspan="2">'.$this->createCaptitalRMB($total_fee).'</td>
                          <td align="center">￥'.sprintf('%.2f',$total_fee).'</td>
                          <td align="center" >报销人</td>
                          <td align="center" >'.$appData['user_name'].'</td>
                        </tr>
                        <tr style="height:20px; line-height: 20px">
                          <td align="center">借款数</td>
                          <td align="center">'.$pre_loan_fee.'</td>
                          <td align="center">应退数</td>
                          <td align="center">'.($loan_fee > 0 ? $loan_fee : 0).'</td>
                          <td align="center">应补金额</td>
                          <td align="center">'.($loan_fee < 0 ? -$loan_fee : 0).'</td>
                        </tr>
                         <tr style="height:20px; line-height: 20px">
                          <td align="center">现金</td>
                          <td align="center">'.($state == 3 ? $appData['fuhe_cash'] : $appData['cash']).'</td>
                          <td align="center">转账</td>
                          <td align="center">'.($state == 3 ? $appData['fuhe_trans_fee'] : $appData['trans']).'</td>
                          <td align="center">公务卡</td>
                          <td align="center">'.($state == 3 ? $appData['fuhe_official'] : $appData['official']).'</td>
                        </tr>
                        </table>
                        <table width="100%" border="0" style="font-size: 10px">
                        <tr>
                           <td align="left">审核人</td>
                           <td align="center"></td>
                           <td align="left">出纳</td>
                            <td align="center"></td>
                            <td align="right">单号</td>
                            <td align="center">'.$appData['fee_id'].'——'.$id.'</td>
                        </tr>
                        </table>';
                $this->pdf->Ln(5);
                $this->pdf->writeHTML($html, true, false, true, false, '');

           // }
        }

        //实际创建差旅报销单的函数
        private function _createBusinessSubmitContent($applyData, $tableData, $id, $hasImage=false)
        {
            $lm = $applyData['loan_money'] - $applyData['total_fee'];
            $self_drive = $applyData['self_drive'];
            $html = '
               <table width="100%" border="0" style="font-size: 20px">
               <tr>
                   <td align="center">
                        <b style="border-bottom:1px solid black">差&nbsp;&nbsp;旅&nbsp;&nbsp;报&nbsp;&nbsp;销&nbsp;&nbsp;单</b>
                        <i style="font-size:10px">单号：'.$applyData['fee_id'].'-'.$id.'</i>
                   </td>
               </tr>
               </table>
               <table width="100%" border="0" style="font-size:10px">
               <tr>
                     <td align="right">部门：</td>
                     <td align="left" colspan="3">'.$applyData['department_name'].'</td>
                     <td align="center" colspan="4">'.date('Y'). '年'.date('m').'月'.date('d').'日</td>
                     <td colspan="2"></td>
                     <td colspan="2" align="right">共计单据: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;张</td>
               
               </tr>     
               </table>
               <table width="100%" border="1" style="font-size:10px">
                <tr>
                    <td align="center">姓名</td>
                    <td align="center" colspan="2">'.$applyData['name'].'</td>
                    <td align="center">出差事由</td>
                    <td align="center" colspan="3">'.$applyData['business_type'].($applyData['case_name'] == '' ? '' : '-'.$applyData['case_name']).'</td>
                    <td align="center" colspan="2">预借差旅</td>
                    <td align="center">'.$applyData['loan_money'].'</td>
                    <td align="center">'.($lm > 0 ? '退' : '补').'</td>
                    <td align="center">'.($lm > 0 ? $lm : -$lm).'</td>
                </tr>
                <tr>
                    <td align="center">出发日期</td>
                    <td align="center">出发地点</td>
                    <td align="center">到达日期</td>
                    <td align="center">到达地点</td>
                    <td align="center">'.($self_drive == 0 ? '车费' : '油费').'</td>
                    <td align="center">'.($self_drive == 0 ? '船费' : '过路费').'</td>
                    <td align="center">'.($self_drive == 0 ? '机票' : '里程数').'</td>
                    <td align="center">天数</td>
                    <td align="center">住宿费用</td>
                    <td align="center">伙食补助</td>
                    <td align="center">公杂费</td>
                    <td align="center">其它</td>
                </tr>';
            $total_boat_fee = 0;
            $total_car_fee = 0;
            $total_flight_fee = 0;
            $total_oil_fee = 0;
            $total_pass_fee = 0;
            $total_distance = 0;
            $total_days = 0;
            $total_hotel_fee = 0;
            $total_meal_fee = 0;
            $total_extra_fee = 0;
            $total_other_fee = 0;
            for ($i = 0; $i < count($tableData); $i++) {
                $row = $tableData[$i];
                $total_days += $row['total_days'];
                $total_car_fee += $row['car_fee'];
                $total_boat_fee += $row['boat_fee'];
                $total_flight_fee += $row['flight_fee'];
                $total_oil_fee += $row['oil_fee'];
                $total_pass_fee += $row['pass_fee'];
                $total_distance += $row['distance'];
                $total_hotel_fee += $row['hotel_fee'];
                $total_meal_fee += $row['food_fee'];
                $total_extra_fee += $row['inci_fee'];
                if($row['other_fee'] === '' || $row['suspect_fee'] === '' ||
                    $row['reward_fee'] === '' || $row['car_main_fee'] === ''){
                    $item_other_fee = '';
                }
                else{
                    $item_other_fee = $row['other_fee'] + $row['suspect_fee'] + $row['reward_fee']
                        + ($self_drive == 1 ? $row['car_main_fee'] : 0);
                }
                $total_other_fee += $item_other_fee;


                $html = $html . '<tr>
                        <td align="center" style="font-size: 10px">' . $row['depart_time'] . '</td>
                        <td align="center" style="font-size: 10px">' . $row['depart_city'] . '</td>
                        <td align="center" style="font-size: 10px">' . $row['arrive_time'] . '</td>
                        <td align="center" style="font-size: 10px">' . $row['arrive_city'] . '</td>
                        <td align="center" style="font-size: 10px">'
                                . ($self_drive == 0 ? $row['car_fee'] : $row['oil_fee']) . '</td>
                        <td align="center" style="font-size: 10px">'
                                . ($self_drive == 0 ? $row['boat_fee'] : $row['pass_fee']) . '</td>
                        <td align="center" style="font-size: 10px">'
                                . ($self_drive == 0 ? $row['flight_fee'] : $row['distance']) . '</td>
                        <td align="center" style="font-size: 10px">' . $row['total_days'] . '</td>
                        <td align="center" style="font-size: 10px">' . $row['hotel_fee'] . '</td>
                        <td align="center" style="font-size: 10px">' . $row['food_fee'] . '</td>
                        <td align="center" style="font-size: 10px">' . $row['inci_fee'] . '</td>
                        <td align="center" style="font-size: 10px">'
                                .  ($item_other_fee === '' ? '' : sprintf('%.2f', $item_other_fee)). '</td>
                    </tr>';
            }
            $html = $html . '<tr>
                        <td align="center">公务卡</td>
                        <td align="center" colspan="2">' . $applyData['official_fee'] . '</td>
                        <td align="center">小计</td>
                        <td align="center" style="font-size: 10px">'
                                . sprintf("%.2f", ($self_drive == 0 ? $total_car_fee : $total_oil_fee)) . '</td>
                        <td align="center" style="font-size: 10px">'
                                . sprintf("%.2f", ($self_drive == 0 ? $total_boat_fee : $total_pass_fee)) . '</td>
                        <td align="center" style="font-size: 10px">'
                                . sprintf("%.2f", ($self_drive == 0 ? $total_flight_fee : $total_distance)) . '</td>
                        <td align="center" style="font-size: 10px">' . sprintf("%d", $total_days) . '</td>
                        <td align="center" style="font-size: 10px">' . sprintf("%.2f", $total_hotel_fee) . '</td>
                        <td align="center" style="font-size: 10px">' . sprintf("%.2f", $total_meal_fee) . '</td>
                        <td align="center" style="font-size: 10px">' . sprintf("%.2f", $total_extra_fee) . '</td>
                        <td align="center" style="font-size: 10px">' .  sprintf("%.2f", $total_other_fee) . '</td>
                    </tr>';

            $html .= '
                    <tr>
                        <td align="center" colspan="2">合计(小写)</td>
                        <td align="center" colspan="2">' . $applyData['total_fee'] . '</td>
                        <td align="center" colspan="2">合计(大写)</td>
                        <td align="center" colspan="6">' . $this->createCaptitalRMB($applyData['total_fee']) . '</td>
                    </tr>
                    <tr>
                        <td align="center"  colspan="1">         
                            <p>部门<br/>审核</p>
                        </td>
                        <td align="center" colspan="3">
                            <div style="text-align:left;line-height:4px"><h2>同意报销</h2></div>
                            <div style="text-align:right;line-height:3px"><p>签批人：'.
                                        ($hasImage ? '<img src="images/sign/'.$applyData['section_manager_ID'].'.jpg" width="60" height="30px">' :
                                            '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img width="60px" height="30px">').'</p></div>'.'
                      
                        </td>
                        <td align="center"  colspan="1">
                            <p>分管<br/>领导</p>
                        </td>
                        <td align="center"  colspan="3" >
                            <div style="text-align:left;line-height:4px"><h2>同意报销</h2></div>
                            <div style="text-align:right;line-height:3px"><p>签批人：'
                                        .($hasImage ? '<img src="images/sign/'.$applyData['section_leader_ID'].'.jpg" width="60" height="30px">' :
                                            '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img width="60px" height="30px">').'</p></div>'.'         
                        </td>
                        <td align="center" colspan="1">
                            <p>签批<br/>领导</p>
                        </td>
                        <td align="center" colspan="3" >
                            <div style="text-align:left;line-height:4px"><h2>同意报销</h2></div>
                            <div style="text-align:right;line-height:3px"><p>签批人：'
                                .($hasImage ? '<img src="images/sign/'.$applyData['leader_ID'].'.jpg" width="60" height="30px">' :
                                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img width="60px" height="30px">').'</p></div>'.'
                        </td>
                    </tr>
                </table>
                <table width="100%" border="0" style="font-size:10px">
                   <tr>
                   <td align="left" colspan="4" >填报人：</td>
                         <td align="left" colspan="4">审核：</td>
                         <td align="left" colspan="4">复核(出纳):</td>
                   </tr>     
               </table>
            <br/>';
            //echo $html;
            $this->pdf->writeHTML($html, true, false, true, false, '');

        }

        //未使用公务卡报销审批单PDF
        function createUnOfiicialPDF($applyData, $hasImage = false){
            $this->pdf->setHeaderData('jinhui.png', 10, '', '宜宾市翠屏区公安局-未使用公务卡强制报销审批单', array(0, 0, 0), array(0, 0, 0));
            $this->pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
            $this->pdf->AddPage();

            // set text shadow effect
            $this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));

            $this->pdf->Ln(5);
            $curWidth = $this->pdf->getPageWidth() - $this->pdf->getMargins()['left'] - $this->pdf->getMargins['right'];
            $curHeight = $this->pdf->getPageHeight() - $this->pdf->getHeaderMargin() - $this->pdf->getFooterMargin();

            $leftWidth = $curWidth / 4;
            $rightWidth = $curWidth / 4 * 3 - $this->pdf->getMargins()['right'];

            $this->pdf->MultiCell($leftWidth, $curHeight / 25, '部门', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25, $applyData['section_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25, 'M');
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 , "填报人", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 , 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 , $applyData['user_name'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 , 'M');

            $fee_info = "
                    <br/><br/><br/><br/><table>
                        <tr>
                             <th>类别</th>
                             <th>实报费用</th>
                             <th>应报费用</th>
                        </tr>
                        <br/>
                        <tr>
                            <td>住宿费：</td>
                            <td>".sprintf('%.2f',$applyData['fee_data']['official_hotel_fee'])."</td>
                            <td>".sprintf('%.2f', $applyData['fee_data']['need_official_hotel_fee'])."</td>
                        </tr>
                        <tr>
                            <td>机票：</td>
                            <td>".sprintf('%.2f',$applyData['fee_data']['official_plane_fee'])."</td>
                            <td>".sprintf('%.2f', $applyData['fee_data']['need_official_plane_fee'])."</td>
                        </tr>
                        <tr>
                           <td>油费：</td>
                            <td>".sprintf('%.2f',$applyData['fee_data']['official_oil_fee'])."</td>
                            <td>".sprintf('%.2f', $applyData['fee_data']['need_official_oil_fee'])."</td>
                        </tr>
                        <tr>
                            <td>车辆维护费：</td>
                            <td>".sprintf('%.2f',$applyData['fee_data']['official_car_maintain_fee'])."</td>
                            <td>".sprintf('%.2f', $applyData['fee_data']['need_official_car_maintain_fee'])."</td>
                        </tr>
                        <br/><br/>
                        <tr>
                            <td>总额:</td>
                            <td>".sprintf('%.2f',$applyData['fee_data']['official_fee'])."</td>
                            <td>".sprintf('%.2f', $applyData['fee_data']['need_official_fee'])."</td>
                        </tr>
                    </table>";
            // $test = "测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n测试1-部门1  测试2-部门2  测试3-部门3\n";
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 6, '费用构成', 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 6, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 6, $fee_info, 1, 'C', 1, 1, '', '', true, 0, true, true, $curHeight / 25 * 6, 'M');

            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 7, "情况说明", 1, 'C', 1, 0, '', '', true, 0, false, true, $curHeight / 25 * 7, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 25 * 7, $applyData['reason'], 1, 'C', 1, 1, '', '', true, 0, false, true, $curHeight / 25 * 7, 'M');


            //文件路径应该获取，分别从三个签批人ID+.jpg获取
            $this->pdf->MultiCell($leftWidth, $curHeight / 25 * 3.75, "部门负责人(签字加盖公章)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_manager_ID'] && $hasImage){
                $this->pdf->Image('images/sign/' . $applyData['section_manager_ID'] . '.jpg',
                    $this->pdf->getMargins()['left'] + 17, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');
            }

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "分局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 0, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');
            if ($applyData['section_leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['section_leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + 35, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->MultiCell($rightWidth / 2, $curHeight / 25 * 3.75, "局领导(签字)<br><h1>&nbsp;&nbsp;&nbsp;&nbsp;同意报销</h1>", 1, 'J', 1, 1, '', '', true, 0, true, true, $curHeight / 25 * 3.75, 'T');

            if ($applyData['leader_ID'] && $hasImage)
                $this->pdf->Image('images/sign/' . $applyData['leader_ID'] . '.jpg', $this->pdf->getMargins()['left'] + $leftWidth + $rightWidth / 2 + 30, $this->pdf->getHeaderMargin() + $curHeight - 50, $leftWidth - 20, $curHeight / 25 * 3.75 - 25, 'JPG');

            $this->pdf->Ln(1);
            $this->pdf->MultiCell($leftWidth, $curHeight / 40, '经办人:', 0, 'J', 1, 0, '', '', true, 0, false, true, $curHeight / 40, 'M');
            $this->pdf->MultiCell($rightWidth, $curHeight / 40, '年             月             日', 0, 'R', 1, 0, '', '', true, 0, false, true, $curHeight / 40);

            $this->pdf->Output(dirname(__FILE__) . '/temp/unofficial/' . $applyData['unuse_official_id'] . '.pdf', 'F');
            return 'PDF/temp/unofficial/' . $applyData['unuse_official_id'] . '.pdf';
        }



}
















?>